#include <iostream>
#include <fstream>
#include "s-clique_free.cpp"
#include "IO.cpp"
#include <vector>
#include <boost/dynamic_bitset.hpp>
#include <string>
#include <ctime>
#include <dirent.h>

using namespace std;

int main(int argc, char** argv)
{
    vector<string> files;
    int s = 7;

    DIR* dir;
    struct dirent* ent;
    if ((dir = opendir ("graphs")) != NULL) {
        while ((ent = readdir (dir)) != NULL) {
	     files.push_back(ent->d_name);
        }
        closedir (dir);
    } else {
        /* could not open directory */
        perror ("");
        return EXIT_FAILURE;
    }

    cout<<files.size()<<endl;


    ofstream fout;
    fout.open("coloringLogFile.log", ofstream::app);
    fout.seekp(0, fout.end);

    clock_t start;
    clock_t end;

    int nodes, edges;

    while(s > 2) {
        for(int i = 0; i < files.size(); ++i) {
            string filename = files[i];
            if(filename.length() < 5)
                continue;
            cout<<filename<<endl;
            vector<dynamic_bitset<> > colorclasses;
            vector<dynamic_bitset<> > graph;
            readgraph_bitset(filename, graph, nodes, edges);
            start = clock();
            s_clique_coloring(graph, colorclasses, s);
            end = clock();
            savecolors(graph, colorclasses, filename, s);
            sorting(graph, colorclasses);
            printgraph_to_pbm(graph, filename, s);
            time_t rawtime;
            struct tm* timeinfo;
            char buffer[80];
            time (&rawtime);
            timeinfo = localtime(&rawtime);
            strftime(buffer,80,"%d-%m-%Y %I:%M:%S",timeinfo);
            string date(buffer);
            fout<<date<<" - Graph: "<<filename<<"\ts: "<<s<<"\tsolution of coloring: ";
            fout<<colorclasses.size()<<"("<<colorclasses.size() * (s-1)<<")";
            fout<<"\tcoloring time: "<<diffclock(end, start)<<endl;
            for(int j = 0; j < nodes; ++j)
                ~graph[j];
            for(int j = 0; j < colorclasses.size(); ++j)
                ~colorclasses[j];
        }
	fout<<endl<<"--------------------"<<endl<<endl;
        --s;
    }

    return 0;
}
